package org.lagou.edu.service;

import org.lagou.edu.controller.dto.ShopInfo;
import org.lagou.edu.utils.ShopGuavaCacheUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @author: oliver
 * @data: 2022/7/16 23:41
 **/
@Service
public class IShopService implements ShopService {

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public ShopInfo queryShop(Long id) {
        ShopInfo info = ShopGuavaCacheUtil.getShop(id);
        if (info != null) {
            return info;
        } else {
            // 查询redis - 并存入本地缓存
            Object o = redisTemplate.opsForValue().get("STOCK_SHOP_INFO:" + id);
            ShopGuavaCacheUtil.setShop(id, o);
            return (ShopInfo) o;
        }
    }
}
